/**
 * Save function
 */
RM.Pages.Functions.enhancedcalendar_config_save = function(){
    RM.Pages.EnhancedCalendar_Config.getForm().submit({
        params: {
            'show_list' : Ext.getDom('rm_pages_enhancedcalendar_config[showonlist]').value,
            'show_details' : Ext.getDom('rm_pages_enhancedcalendar_config[showondetails]').value,
            'show_day' : Ext.getDom('rm_pages_enhancedcalendar_config[showday]').value,
            'show_week' : Ext.getDom('rm_pages_enhancedcalendar_config[showweek]').value,
            'show_twoweek' : Ext.getDom('rm_pages_enhancedcalendar_config[showtwoweek]').value,
            'show_month' : Ext.getDom('rm_pages_enhancedcalendar_config[showmonth]').value,
            'read_only' : Ext.getDom('rm_pages_enhancedcalendar_config[readonly]').value,
            'showhelp_popup' : Ext.getDom('rm_pages_enhancedcalendar_config[showhelppopup]').value,
            'close_onselect' : Ext.getDom('rm_pages_enhancedcalendar_config[closeonselect]').value,
            'fullday_starttime' :  Ext.getCmp("rm_pages_enhancedcalendar_config[fulldaystarttime]").getValue(),
            'fullday_endtime' : Ext.getCmp("rm_pages_enhancedcalendar_config[fulldayendtime]").getValue()
        },
        success: function(form, action) {
            Ext.getCmp('rm_pages_config_edit_statusbar').setStatus({
                text: RM.Translate.Common.Saved,
                iconCls: 'ok-icon'
            });
        },
        waitMsg: RM.Translate.Common.Saving,
        waitTitle: RM.Translate.Common.PleaseWait
    });
}

/**
 * Toolbar definition
 */
RM.Pages.EnhancedCalendar_Config_Toolbar = {
    xtype : "panel",
    id : "rm_pages_enhancedcalendar_config_toolbar",
    bodyBorder : false,
    html : RM.Common.getToolbar([{image: RM.BaseLargeImageURL+"save.gif", label: RM.Translate.Common.Save, link: "RM.Pages.Functions.enhancedcalendar_config_save()"}])
}
RM.Toolbars.push(RM.Pages.EnhancedCalendar_Config_Toolbar);

// form feilds
RM.Pages.EnhancedCalendar_Config_ShowOnList = {
    id: "rm_pages_enhancedcalendar_config[showonlist]",
    name: "rm_pages_enhancedcalendar_config_showonlist",
    inputValue: "1",
    fieldLabel: RM.Translate.Admin.EnhancedCalendar.Main.ShowOnList,
    xtype: "xcheckbox"
};
RM.Pages.EnhancedCalendar_Config_ShowOnDetails = {
    id: "rm_pages_enhancedcalendar_config[showondetails]",
    name: "rm_pages_enhancedcalendar_config_showondetails",
    inputValue: "1",
    fieldLabel: RM.Translate.Admin.EnhancedCalendar.Main.ShowOnDetails,
    
    xtype: "xcheckbox"
};
RM.Pages.EnhancedCalendar_Config_ShowDays = {
    id: "rm_pages_enhancedcalendar_config[showday]",
    name: "rm_pages_enhancedcalendar_config_showday",
    inputValue: "1",
    fieldLabel: RM.Translate.Admin.EnhancedCalendar.Main.ShowDays,
    xtype: "xcheckbox"
};
RM.Pages.EnhancedCalendar_Config_ShowWeeks = {
    id: "rm_pages_enhancedcalendar_config[showweek]",
    name: "rm_pages_enhancedcalendar_config_showweek",
    inputValue: "1",
    fieldLabel: RM.Translate.Admin.EnhancedCalendar.Main.ShowWeeks,
    xtype: "xcheckbox"
};
RM.Pages.EnhancedCalendar_Config_ShowTwoWeeks = {
    id: "rm_pages_enhancedcalendar_config[showtwoweek]",
    name: "rm_pages_enhancedcalendar_config_showtwoweek",
    inputValue: "1",
    fieldLabel: RM.Translate.Admin.EnhancedCalendar.Main.ShowTwoWeeks,
    xtype: "xcheckbox"
};
RM.Pages.EnhancedCalendar_Config_ShowMonths = {
    id: "rm_pages_enhancedcalendar_config[showmonth]",
    name: "rm_pages_enhancedcalendar_config_showmonth",
    inputValue: "1",
    fieldLabel: RM.Translate.Admin.EnhancedCalendar.Main.ShowMonths,
    xtype: "xcheckbox"
};
RM.Pages.EnhancedCalendar_Config_ReadOnly = {
    id: "rm_pages_enhancedcalendar_config[readonly]",
    name: "rm_pages_enhancedcalendar_config_readonly",
    inputValue: "1",
    fieldLabel: RM.Translate.Admin.EnhancedCalendar.Main.ReadOnly,
    xtype: "xcheckbox"
};
RM.Pages.EnhancedCalendar_Config_ShowHelpPopup = {
    id: "rm_pages_enhancedcalendar_config[showhelppopup]",
    name: "rm_pages_enhancedcalendar_config_showhelppopup",
    inputValue: "1",
    fieldLabel: RM.Translate.Admin.EnhancedCalendar.Main.ShowHelpPopup,
    xtype: "xcheckbox"
};
RM.Pages.EnhancedCalendar_Config_CloseOnSelect = {
    id: "rm_pages_enhancedcalendar_config[closeonselect]",
    name: "rm_pages_enhancedcalendar_config_closeonselect",
    inputValue: "1",
    fieldLabel: RM.Translate.Admin.EnhancedCalendar.Main.CloseOnSelection,
    xtype: "xcheckbox"
};

RM.Pages.EnhancedCalendar_Config_FullDayStartTime = {
    xtype : "textfield",
    id : "rm_pages_enhancedcalendar_config[fulldaystarttime]",
    name : "rm_pages_enhancedcalendar_config[fulldaystarttime]",
    fieldLabel : RM.Translate.Admin.EnhancedCalendar.Main.FullDayStartTime,
    width : 100
}
RM.Pages.EnhancedCalendar_Config_FullDayEndTime = {
    xtype : "textfield",
    id : "rm_pages_enhancedcalendar_config[fulldayendtime]",
    name : "rm_pages_enhancedcalendar_config[fulldayendtime]",
    fieldLabel : RM.Translate.Admin.EnhancedCalendar.Main.FullDayEndTime,
    width : 100
}


/**
 * load form data function
 */
RM.Pages.Functions.EnhancedCalendar_ConfigJson = function (responseObject) {

    // create a mask assigned to rm_pages_plugins_paypal_main_form
    var myMask = new Ext.LoadMask('rm_pages_enhancedcalendar_config', {
        msg: RM.Translate.Common.PleaseWait,
        msgCls: "RM_Loading_Mask_Msg_Hidden" // hide the msg
    });
    // enable the mask while the data and form are loaded
    myMask.show();

    // the data is contained in the responseObject
    var settings = responseObject.settings[0];

    // set the values of the form items
    Ext.getCmp("rm_pages_enhancedcalendar_config[showonlist]").setValue(settings.show_list);
    Ext.getCmp("rm_pages_enhancedcalendar_config[showondetails]").setValue(settings.show_details);
    Ext.getCmp("rm_pages_enhancedcalendar_config[showday]").setValue(settings.show_day);
    Ext.getCmp("rm_pages_enhancedcalendar_config[showweek]").setValue(settings.show_week);
    Ext.getCmp("rm_pages_enhancedcalendar_config[showtwoweek]").setValue(settings.show_twoweek);
    Ext.getCmp("rm_pages_enhancedcalendar_config[showmonth]").setValue(settings.show_month);
    Ext.getCmp("rm_pages_enhancedcalendar_config[readonly]").setValue(settings.read_only);
    Ext.getCmp("rm_pages_enhancedcalendar_config[showhelppopup]").setValue(settings.showhelp_popup);
    Ext.getCmp("rm_pages_enhancedcalendar_config[closeonselect]").setValue(settings.close_onselect);
    Ext.getCmp("rm_pages_enhancedcalendar_config[fulldaystarttime]").setValue(settings.fullday_starttime);
    Ext.getCmp("rm_pages_enhancedcalendar_config[fulldayendtime]").setValue(settings.fullday_endtime);

    // just do so Extjs stuff to ensure the GUI is rendered and visable
    Ext.getCmp('rm_pages_enhancedcalendar_config').render();
    Ext.getCmp('rm_pages_enhancedcalendar_config').doLayout();


    Ext.getCmp('rm_pages_enhancedcalendar_config_fieldset').doLayout();
    Ext.getCmp('content-panel').layout.setActiveItem('rm_pages_enhancedcalendar_config');
    Ext.getCmp('toolbar_panel').layout.setActiveItem('rm_pages_enhancedcalendar_config_toolbar');


    // hide the mask
    myMask.hide();

}

/**
 * the page fieldset this is where the form feilds will be rendered
 */
RM.Pages.EnhancedCalendar_Config_Fieldset = new Ext.form.FieldSet({
    id: "rm_pages_enhancedcalendar_config_fieldset",
    title: RM.Translate.Admin.EnhancedCalendar.Main.Settings,
    autoHeight: true,
    layout: 'form',
    bodyBorder : false,
    LabelWidth: 250,
    items: [
        RM.Pages.EnhancedCalendar_Config_ShowOnList,
        RM.Pages.EnhancedCalendar_Config_ShowOnDetails,
        RM.Pages.EnhancedCalendar_Config_ShowDays,
        RM.Pages.EnhancedCalendar_Config_ShowWeeks,
        RM.Pages.EnhancedCalendar_Config_ShowTwoWeeks,
        RM.Pages.EnhancedCalendar_Config_ShowMonths,
        RM.Pages.EnhancedCalendar_Config_ReadOnly,
        RM.Pages.EnhancedCalendar_Config_ShowHelpPopup,
        RM.Pages.EnhancedCalendar_Config_CloseOnSelect,
        RM.Pages.EnhancedCalendar_Config_FullDayStartTime,
        RM.Pages.EnhancedCalendar_Config_FullDayEndTime
    ]
});

/**
 * the main config panel
 */
RM.Pages.EnhancedCalendar_Config = new Ext.FormPanel({
    id : "rm_pages_enhancedcalendar_config",
    title: RM.Translate.Admin.EnhancedCalendar.Main.ConfigTitle,
    bodyStyle : "padding:10px;",
    url : RM.Common.AssembleURL({
        controller: 'EnhancedCalendar',
        action: 'configupdatejson'
    }),
    labelWidth: 250,
    autoScroll: true,
    items : [RM.Pages.EnhancedCalendar_Config_Fieldset]
});

RM.Main.Pages.push(RM.Pages.EnhancedCalendar_Config);